//
//  NetworkTools+Status.swift
//  WeiBo2017
//
//  Created by 王璐 on 2017/5/2.
//  Copyright © 2017年 wl. All rights reserved.
//

import Foundation

extension NetworkTools{
    
    /// 加载微博数据
    ///
    /// - parameter since_id: 若指定此参数，则返回ID比since_id "大" 的微博（即比since_id时间晚的微博），默认为0。
    /// - parameter max_id:   若指定此参数，则返回ID "小于或等于" max_id的微博，默认为0。
    /// - parameter finished: 完成回调(字典)
    func loadStatus( since_id:Int64 = 0,max_id:Int64 = 0,finished:@escaping ([String:AnyObject]?)->()){
        
        /// 判断access_token是否存在,如果不存在,用户没有登录
        //TODO: - 出理access_token过期
        guard let access_token = UserCount.sharedUserCount.access_token else{
            
            return
        }
        
        let urlString = "https://api.weibo.com/2/statuses/home_timeline.json"
        var parms :[String:AnyObject] = ["access_token":access_token as AnyObject]
        
        //判断下拉id
        if since_id > 0 {
            parms["since_id"] =  since_id as AnyObject?
        }
        //判断上拉id
        if max_id > 0 {
            parms["max_id"] = max_id-1 as AnyObject?
        }
        
        request(method: .GET, urlString: urlString, parameters: parms as [String : AnyObject]?, finished: finished)
        
    }
    
}
